home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 90 / CDMM_90_1.ISO / Cycling Manager 2 / CyclingManager2Demo.exe / Disk1 / data1.cab / Game / DataCM2 / scripts / net / lan.cnc < prev    next >
Encoding:
Text File  |  2002-05-10  |  2.7 KB  |  105 lines

  1. // ** Lan Server **
  2.  
  3. // * functions 
  4.  
  5. func void fnLanBroadcast_CreateReceiver()
  6. {
  7.     /*if (!g_pLanUDPServer)
  8.     {
  9.         g_pLanUDPServer = NetUDPServer_Constructor(G_iLanBroadcastPort, fnLanBroadcastCB);
  10.     }*/
  11. }
  12.  
  13. func void fnLanBroadcast_DestroyReceiver()
  14. {
  15.     /*if (g_pLanUDPServer)
  16.     {
  17.         NetUDPServer_Destructor(g_pLanUDPServer);
  18.         g_pLanUDPServer = g_pNullUDPServer;
  19.     }*/
  20. }
  21.  
  22. // * callbacks
  23.  
  24. // reception from an udp broadcast : connect to the same ip and to the given port
  25. func void fnLanBroadcastCB(szx szIP, i32x iPort, szx szString)
  26. {
  27.     var Net_Client pClient;
  28.     iPort = atoi(szString);
  29.     if (iPort>0)
  30.     {
  31.         /*pClient = NetClient_CreateObsolete(
  32.             szIP,
  33.             iPort, 
  34.             NullInterface, 
  35.             LanBroadcastConnectCB, 
  36.             LanBroadcastDisconnectCB);*/
  37.     }
  38. }
  39.  
  40. func void LanBroadcastConnectCB(Net_Client pClient)
  41. {
  42.     // tutu debug : should look in local Menu Server
  43.     var i32x iNumConnected;
  44.     iNumConnected = 0;
  45.  
  46.     // give game parameters
  47.     pClient << mLanGame(Join_GetStringFromIndex( g_oLocalJoins.m_iUser_szName, 0),g_iServerPort,g_oGameConfig.m_iGameMode,iNumConnected);
  48. }
  49.  
  50. func void LanBroadcastDisconnectCB(Net_Client pClient)
  51. {
  52. }
  53.  
  54.  
  55. // ** Lan Client **
  56.  
  57.  
  58. func void fnLanBroadcast()
  59. {
  60.     var Net_UDPClient pClient;
  61.     var i32x iGamesTable;
  62.  
  63.     // broadcast lobby port
  64.     pClient = NetUDPClient_Constructor("*",G_iLanBroadcastPort);
  65.     //NetUDPClient_SendString(pClient,itoa(g_iServerPort));
  66.     NetUDPClient_Destructor(pClient);
  67.  
  68.     // reset games
  69.     iGamesTable = Table_GetIndexFromName(QUERY_GAME_SERVERS,"Games");
  70.     Table_DeleteAllRows(QUERY_GAME_SERVERS, iGamesTable);
  71.     Database_DeleteNow(QUERY_GAME_SERVERS);
  72. }
  73.  
  74.  
  75. func void fnGateway_LanGame(szx szName,i32x iPort,i32x iGameMode,i32x _iNumConnected)
  76. {
  77.     print("lan game name:");println(szName);
  78.     print("lan game port:");println(itoa(iPort));
  79.     print("lan game mode:");println(itoa(iGameMode));
  80.     print("lan game connected:");println(itoa(_iNumConnected));
  81.  
  82.     var Net_Client pClient;
  83.     var szx szIp;
  84.     var i32x iTableGame, iNewRow;
  85.  
  86.     pClient = GetCurrentClient();
  87.     szIp = NetClient_GetDistantIP(pClient);
  88.     print("lan game ip:");println(szIp);
  89.  
  90.     iTableGame = Table_GetIndexFromName(QUERY_GAME_SERVERS,"Games");
  91.     iNewRow =    Table_AddRow(QUERY_GAME_SERVERS,iTableGame);
  92.  
  93.     Join_SetStringFromIndex(    g_oGatewayJoins.m_iGame_szDescJoin, iNewRow, szName);
  94.     Join_SetIntFromIndex(        g_oGatewayJoins.iGameMode,            iNewRow, iGameMode);
  95.     Join_SetIntFromIndex(        g_oGatewayJoins.bHasPassword,        iNewRow, 0);
  96.     Join_SetStringFromIndex(    g_oGatewayJoins.szIP,                iNewRow, szIp);
  97.     Join_SetIntFromIndex(        g_oGatewayJoins.iPort,                iNewRow, iPort);
  98.     Join_SetIntFromIndex(        g_oGatewayJoins.iNumConnected,        iNewRow, _iNumConnected);
  99.  
  100.     NetClient_Disconnect(pClient);
  101. }
  102.  
  103.  
  104.  
  105.